
package com.wyzz.hr.base.wf;

import java.util.*;
import javax.servlet.http.HttpSession;

import com.wyzz.hr.base.BaseDownloadAction;
import com.wyzz.hr.bo.IEmpApproverBo;
import com.wyzz.hr.bo.IPositionBo;
import com.wyzz.hr.bo.IWorkFlowBO;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Leaverequest;
import com.wyzz.hr.pojo.Overtimerequest;
import com.wyzz.hr.pojo.Position;
import com.wyzz.hr.pojo.Recruitplan;
import com.wyzz.hr.pojo.Tremployeeplan;
import com.wyzz.hr.pojo.WorkFlowApprover;
import com.wyzz.hr.spring.SpringBeanFactory;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.SysConfigManager;
import com.wyzz.hr.vo.LeaveFormBean;
import com.wyzz.hr.vo.OvertimeFormBean;
import com.wyzz.hr.vo.RecruitFormBean;
import com.wyzz.hr.vo.TrainFormBean;


public abstract class AbstractWfApproverAction extends BaseDownloadAction {

	public AbstractWfApproverAction() {
		authorityCondition = null;
		dbConfigManager = DatabaseSysConfigManager.getInstance();
	}

	public abstract String beforeInit(String s, Object obj);

	public Leaverequest objInit(String operate, LeaveFormBean lf_Bean,
			String lrUpdateId) {
		return null;
	}

	public List objInit(String operate, TrainFormBean tr_Bean, String trUpdateId) {
		return null;
	}

	public Recruitplan objInit(String operate, RecruitFormBean rec_Bean,
			String recpUpdateId) {
		return null;
	}

	public Overtimerequest objInit(String operate, OvertimeFormBean of_Bean,
			String orUpdateId) {
		return null;
	}

	public abstract String afterInit(Object aobj[]);

	public abstract String wfObjOpBatch(String s, Object obj, String as[]);

	public String wfObjOperate(Object objList[]) {
		if (objList.length == 0) {
			return "input";
		} else {
			IEmpApproverBo bo = (IEmpApproverBo) getBean("empApproverBo");
			Map msgMap = bo.saveOrUpdateFlowData(objList);
			msgMapToInfo(msgMap);
			return "success";
		}
	}

	private void msgMapToInfo(Map msgMap) {
		for (Iterator iterator = msgMap.keySet().iterator(); iterator.hasNext();) {
			String msg = (String) iterator.next();
			String var = ((StringBuffer) msgMap.get(msg)).toString();
			if (msg.contains("\u64CD\u4F5C\u5931\u8D25"))
				addErrorInfo(msg, new Object[] { var });
			else
				addSuccessInfo(msg, new Object[] { var });
		}

	}

	public abstract String wfObjOpSingle(String s, Object obj, String s1);

	protected boolean wfInit(String operate, String comment, Object objList[]) {
		String msgStatusErr = "\u7F16\u53F7\u4E3A{0}\u7684{1}\u72B6\u6001\u9519\u8BEF\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\uFF01";
		String msgNoCharge = "\u60A8\u65E0\u6743\u5904\u7406{0}\u7684{1}\uFF01";
		String msgNoChargeRecp = "NOAUTH:\u60A8\u65E0\u6743\u5904\u7406\u8BE5\u62DB\u8058\u7533\u8BF7\uFF01";
		if (objList == null || objList.length == 0)
			return false;
		Employee currentEmp = operatorInit(operate, objList[0],
				getCurrentEmp(), new Position(getCurrentPosNo()));
		Date lastChangeTime = new Date();
		Object arr$[] = objList;
		int len$ = arr$.length;
		for (int i$ = 0; i$ < len$; i$++) {
			Object obj = arr$[i$];
			AbstractWorkflow wf = AbstractWorkflow.getWorkFlow(obj, operate,
					comment, currentEmp, lastChangeTime);
			if (!AbstractWorkflow.wfRelationCheck(wf)) {
				if (wf.getFlowType().equals("recruitrequest"))
					addErrorInfo(msgNoChargeRecp);
				else
					addErrorInfo(msgNoCharge, new Object[] {
							wf.getApplier().getEmpName(), wf.getDocDesc() });
				return false;
			}
			if (!AbstractWorkflow.wfStatusCheck(wf)) {
				addErrorInfo(msgStatusErr, new Object[] { wf.getDocNo(),
						wf.getDocDesc() });
				return false;
			}
		}

		return true;
	}

	public Employee operatorInit(String operate, Object obj,
			Employee currentEmp, Position pos) {
		currentEmp.setPosition(pos);
		String flowType = AbstractWorkflow.getFlowType(obj);
		if ("hr-create".equals(operate) || "hr-update".equals(operate)
				|| operate.contains("mgr-")) {
			IPositionBo posBo = (IPositionBo) SpringBeanFactory
					.getBean("positionBo");
			String empInCharge[] = posBo.getAllSubEmpIds(0, pos.getId());
			currentEmp.setEmpInCharge(empInCharge);
			IWorkFlowBO workflowBo = (IWorkFlowBO) SpringBeanFactory
					.getBean("workFlowBO");
			WorkFlowApprover wfapprover = workflowBo.getWfApproverById(
					currentEmp.getPosition().getId(), flowType);
			if (wfapprover != null)
				currentEmp.setHasApproveAuth(true);
			else
				currentEmp.setHasApproveAuth(false);
		}
		return currentEmp;
	}

	public Leaverequest initLfBean(String operate, LeaveFormBean lf_Bean,
			String lrId) {
		return null;
	}

	public Overtimerequest initOfBean(String operate, OvertimeFormBean of_Bean,
			String orId) {
		return null;
	}

	public Tremployeeplan initTrBean(String operate, TrainFormBean tr_Bean,
			String trId) {
		return null;
	}

	public String getSuccessPath() {
		String mode = dbConfigManager.getProperty("sys.examin.shift.enable");
		if (mode.startsWith("1"))
			return "successByHourMode";
		else
			return "success";
	}

	public Leaverequest getLRContext(String lrID, HttpSession session) {
		return null;
	}

	public Overtimerequest getOTContext(String otID, HttpSession session) {
		return null;
	}

	public String approveOrReject(String actionName, String operate, String id,
			String s, HttpSession httpsession) {
		return null;
	}

	public String DWRwfObjOpSingle(String operate, String comment,
			String employeeId, String s, String s1, String s2) {
		return null;
	}

	public String getAuthorityCondition() {
		return authorityCondition;
	}

	public void setAuthorityCondition(String authorityCondition) {
		this.authorityCondition = authorityCondition;
	}

	public List getDeptList() {
		return deptList;
	}

	public void setDeptList(List deptList) {
		this.deptList = deptList;
	}

	public List getOtTypeList() {
		return otTypeList;
	}

	public void setOtTypeList(List otTypeList) {
		this.otTypeList = otTypeList;
	}

	public List getLrTypeList() {
		return lrTypeList;
	}

	public void setLrTypeList(List lrTypeList) {
		this.lrTypeList = lrTypeList;
	}

	public List getLrStatusList() {
		return lrStatusList;
	}

	public void setLrStatusList(List lrStatusList) {
		this.lrStatusList = lrStatusList;
	}

	public List getOtStatusList() {
		return otStatusList;
	}

	public void setOtStatusList(List otStatusList) {
		this.otStatusList = otStatusList;
	}

	public List getStatusList() {
		return statusList;
	}

	public void setStatusList(List statusList) {
		this.statusList = statusList;
	}

	public Map getStatusMap() {
		return statusMap;
	}

	public void setStatusMap(Map statusMap) {
		this.statusMap = statusMap;
	}

	public SysConfigManager getDbConfigManager() {
		return dbConfigManager;
	}

	public void setDbConfigManager(SysConfigManager dbConfigManager) {
		this.dbConfigManager = dbConfigManager;
	}

	public String getInfoMeg() {
		return infoMeg;
	}

	public void setInfoMeg(String infoMeg) {
		this.infoMeg = infoMeg;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getLeaveType() {
		return leaveType;
	}

	public void setLeaveType(String leaveType) {
		this.leaveType = leaveType;
	}

	private static final long serialVersionUID = 1L;
	public static final String SUCCESSByHourMode = "successByHourMode";
	protected final String AUTHMODULE = "411";
	protected final String AUTHCONDITION = "3";
	protected String authorityCondition;
	protected List deptList;
	protected List otTypeList;
	protected List lrTypeList;
	protected List lrStatusList;
	protected List otStatusList;
	protected List statusList;
	protected Map statusMap;
	protected SysConfigManager dbConfigManager;
	protected String infoMeg;
	protected String errorMsg;
	protected String leaveType;
}
